*Comment coding (data not uploaded to protect anonymity)

gen length=strlen(comment)
gen lengthlog=log(length)
recode lengthlog .=0

*Violence
gen violreply3=0 if violence~=""
recode violreply3 0=1 if violence=="Violence at a commenter"
recode violreply3 0=.5 if violence1=="Violence at a commenter"|violence2=="Violence at a commenter"
replace violreply3=0 if violence1=="Violence at a commenter" & (violence2=="Violence at police"|violence2=="Violence at protesters"|violence2=="Call for NON-violence")
replace violreply3=0 if violence2=="Violence at a commenter" & (violence1=="Violence at police"|violence1=="Violence at protesters"|violence1=="Call for NON-violence")
gen violreplyagree=violreply3
recode violreplyagree 0=0 .5=0 1=1

gen violpol3=0 if violence~=""
recode violpol3 0=1 if violence=="Violence at police"
recode violpol3 0=.5 if violence1=="Violence at police"|violence2=="Violence at police"
replace violpol3=0 if violence1=="Violence at police" & (violence2=="Violence at a commenter"|violence2=="Violence at protesters"|violence2=="Call for NON-violence")
replace violpol3=0 if violence2=="Violence at police" & (violence1=="Violence at a commenter"|violence1=="Violence at protesters"|violence1=="Call for NON-violence")
gen violpolagree=violpol3
recode violpolagree 0=0 .5=0 1=1

gen violprot3=0 if violence~=""
recode violprot3 0=1 if violence=="Violence at protesters"
recode violprot3 0=.5 if violence1=="Violence at protesters"|violence2=="Violence at protesters"
replace violprot3=0 if violence1=="Violence at protesters" & (violence2=="Violence at a commenter"|violence2=="Violence at police"|violence2=="Call for NON-violence")
replace violprot3=0 if violence2=="Violence at protesters" & (violence1=="Violence at a commenter"|violence1=="Violence at police"|violence1=="Call for NON-violence")
gen violprotagree=violprot3
recode violprotagree 0=0 .5=0 1=1

gen violanyagree=(violreplyagree+violpolagree+violprotagree)
recode violanyagree 3 2=1

gen nonviol3=0 if violence~=""
recode nonviol3 0=1 if violence=="Call for NON-violence"
recode nonviol3 0=.5 if violence1=="Call for NON-violence"|violence2=="Call for NON-violence"
replace nonviol3=0 if violence1=="Call for NON-violence" & (violence2=="Violence at a commenter"|violence2=="Violence at police"|violence2=="Violence at protesters")
replace nonviol3=0 if violence2=="Call for NON-violence" & (violence1=="Violence at a commenter"|violence1=="Violence at police"|violence1=="Violence at protesters")
gen nonviolagree=nonviol3
recode nonviolagree 0=0 .5=0 1=1

*Force
gen force3=0 if force~=""
recode force3 0=1 if force=="Want more force used"
recode force3 0=-1 if force=="Want less force used"
recode force3 0=.5 if force1=="Want more force used"|force2=="Want more force used"
recode force3 0=-.5 if force1=="Want less force used"|force2=="Want less force used"
gen forceagree=force3
recode forceagree 0=0 -.5 .5=0 1=1 -1=-1

gen moreforceagree=0 if force~=""
recode moreforceagree 0=1 if force=="Want more force used"

gen lessforceagree=0 if force~=""
recode lessforceagree 0=1 if force=="Want less force used"

*Justify Killing
gen killjustagree=0 if justify~=""
recode killjustagree 0=1 if justify=="Killing was justified"
recode killjustagree 0=-1 if justify=="Killing was unjustified"

gen justkillagree=killjustagree
recode justkillagree -1=0

gen unjustkillagree=killjustagree
recode unjustkillagree -1=1 1=0

*Insult
gen insult3=0 if insult~=""
recode insult3 0=1 if insult=="Yes, insulting"
recode insult3 0=.5 if insult1=="Yes, insulting"|insult2=="Yes, insulting"
gen insultagree=insult3
recode insultagree 0=0 .5=0 1=1

*Peace
gen peace3=0 if peace~=""
recode peace3 0=1 if peace=="Yes"
recode peace3 0=.5 if peace1=="Yes"|peace2=="Yes"
gen peaceagree=peace3
recode peaceagree 0=0 .5=0 1=1

*Negative by Race
gen negraceany3=0 if negrace~=""
recode negraceany3 0=1 if negrace~="No, or not clear" & negrace~="no_agreement"
recode negraceany3 0=.5 if negrace=="no_agreement"
gen negraceanyagree=negraceany3
recode negraceanyagree 0=0 .5=0 1=1

gen negraceblk3=0 if negrace~=""
recode negraceblk3 0=1 if negrace=="Yes, toward black folks"
recode negraceblk3 0=.5 if negrace1=="Yes, toward black folks" | negrace2=="Yes, toward black folks"

gen negraceblkagree=negraceblk3
recode negraceblkagree 0=0 .5=0 1=1

gen negracewht3=0 if negrace~=""
recode negracewht3 0=1 if negrace=="Yes, toward white folks" 
recode negracewht3 0=.5 if negrace1=="Yes, toward white folks" | negrace2=="Yes, toward white folks"

gen negracewhtagree=negracewht3
recode negracewhtagree 0=0 .5=0 1=1

gen negraceboth3=0 if negrace~=""
recode negraceboth3 0=1 if negrace=="Yes, toward white & black" 
recode negraceboth3 0=.5 if negrace1=="Yes, toward white & black" | negrace2=="Yes, toward white & black"

gen negracebothagree=negraceboth3
recode negracebothagree 0=0 .5=0 1=1

*Percentages of Views
gen equalityagree=0
recode equalityagree 0=1 if (equal1=="More needs to be done" & equal2=="More needs to be done") 
recode equalityagree 0=-1 if (equal1=="Gone too far on rights" & equal2=="Gone too far on rights")
recode equalityagree 0=-.5 if (equal1=="Race equality is reached" & equal2=="Race equality is reached")

gen newsviewagree=0 if news~=""
recode newsviewagree 0=1 if (news1=="Praises news coverage" & news2=="Praises news coverage") 
recode newsviewagree 0=-1 if (news1=="Criticizes news coverage" & news2=="Criticizes news coverage") 

gen protestagree=0 if protesters~=""
recode protestagree 0=1 if protesters1=="Supports protesters" & protesters2=="Supports protesters"
recode protestagree 0=-1 if protesters1=="Criticizes protesters" & protesters2=="Criticizes protesters"

gen policeagree=0 if police~=""
recode policeagree 0=1 if police1=="Supports police" & police2=="Supports police"
recode policeagree 0=-1 if police1=="Criticizes police" & police2=="Criticizes police"



*DEMOGRAPHICS
rename age ageguess
gen age=2016-birth
replace age=ageguess if age==.
tab age

gen agemiss=0
recode agemiss 0=1 if age==.

gen age1839=age
recode age1839 18/39=1 40/100=0
recode age1839 .=0 if agemiss==1

gen age4059=age
recode age4059 40/59=1 18/39 60/100=0
recode age4059 .=0 if agemiss==1

gen age60plus=age
recode age60plus 60/100=1 18/59=0
recode age60plus .=0 if agemiss==1

gen fem=sex
recode fem 0=0 1=1 2 9=.

tab married
replace married=0 if married==. & fbid~=""

gen local=lives
recode local 1 2=1 3/6=0
replace local=0 if local==. & fbid~=""
gen louisiana=lives
recode louisiana 1/3=1 4/6=0
replace louisiana=0 if louisiana==. & fbid~=""

tab college
replace college=0 if college==. & fbid~=""

gen white=race
recode white 1=1 2/9=0
replace white=0 if white==. & fbid~=""
gen black=race
recode black 2=1 1 3/9=0
replace black=0 if black==. & fbid~=""

gen christian=religion
recode christian 1=1 2 3=0
replace christian=0 if christian==. & fbid~=""
